package com.xinyue.auto.reader.process;

import com.xinyue.auto.exception.ManyManyException;
import com.xinyue.auto.reader.Process;
import com.xinyue.auto.reader.ProcessContext;
import com.xinyue.auto.util.StringUtil;

public class ManyInitProcess extends ProcessContext{
	public ManyInitProcess(Process read) {
		super(read);
	}
	
	private String name;//many-many name
	private String table;//表名称

	@Override
	protected void validate() throws Exception {
		name = xml.attributeValue(name_);
		table = xml.attributeValue(table_);
		
		if(StringUtil.isNull(name)) {
			throw new ManyManyException("未定义name属性或其值为空", holder.getException());
		}
		if(StringUtil.isNull(table)) {
			table = name;
		}
		
		//设置异常信息中的entity名称
		holder.getException().setEntityName(name);
	}

	@Override
	protected void install() {
		//entity类型：1
		holder.getEntity().setType(manyType);
		
		holder.getEntity().setName(name);
		holder.getEntity().setTable(table);
	}
}
